package toanstt.shop;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.view.MotionEvent;
import toanstt.com.App;
import toanstt.com.Button;
import toanstt.com.CallBackFunction;
import toanstt.com.DiamondLinkinActivity;
import toanstt.com.SCR;
import toanstt.com.T;
import toanstt.mainframe.MenuPannel;

public class Shop
{
	static public Shoppannel shoppanel;
	
	int temp_x, temp_y;
	MenuPannel menupanel;
	static public Button unlockcell;
	static public Button luckkycell;
	static public Button manasize;
	static public Button boomsize;
	static public Button magicsize;
	public Shop()
	{
		shoppanel = new Shoppannel();
		unlockcell =new Button(T.bitmap_button_shop_ulockcell, (int)(T.GAMESCREEN_MIN_X + 12*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 4*T.UNIT), 4*T.UNIT/80);
		unlockcell.SetString(12+" Unlocked cell left",(int)(0.4*T.UNIT),(int)(2.4*T.UNIT),5);
		
		luckkycell =new Button(T.bitmap_button_shop_lucky, (int)(T.GAMESCREEN_MIN_X + 12*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 9*T.UNIT), 4*T.UNIT/80);
		luckkycell.SetString("Your chance: " + T.PLAY_LUCKY,(int)(0.4*T.UNIT),(int)(2.4*T.UNIT),5);
		
		manasize =new Button(T.bitmap_button_shop_manasize, (int)(T.GAMESCREEN_MIN_X + 12*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 14*T.UNIT), 4*T.UNIT/80);
		manasize.SetString("Your mana : " + T.PLAY_MANASIZE,(int)(0.4*T.UNIT),(int)(2.4*T.UNIT),5);
		
		boomsize =new Button(T.bitmap_button_shop_boomsize, (int)(T.GAMESCREEN_MIN_X + 12*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 19*T.UNIT), 4*T.UNIT/80);
		boomsize.SetString("Your boom range : " + T.PLAY_BOOM_LEVEL,(int)(0.4*T.UNIT),(int)(2.4*T.UNIT),5);
		
		magicsize =new Button(T.bitmap_button_shop_magicsize, (int)(T.GAMESCREEN_MIN_X + 12*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 24*T.UNIT), 4*T.UNIT/80);
		magicsize.SetString("Your magic range : " + T.PLAY_MAGIC_LEVEL,(int)(0.4*T.UNIT),(int)(2.4*T.UNIT),5);
		
	}
	public void Draw(Canvas canvas)
	{
		
		
		{
			if(T.PLAY_GOLD<5000)
				unlockcell.isdisible = true;
			else
				unlockcell.isdisible = false;
		}
		
		
		{
			if(T.PLAY_GOLD<10000)
				luckkycell.isdisible = true;
			else
				luckkycell.isdisible = false;
		}
		
		if(T.PLAY_GOLD<5000)
			boomsize.isdisible = true;
		else
			boomsize.isdisible = false;
		
		if(T.PLAY_GOLD<30000)
			magicsize.isdisible = true;
		else
			magicsize.isdisible = false;
		
		
		if(T.PLAY_GOLD<20000)
			manasize.isdisible = true;
		else
			manasize.isdisible = false;
		
		
		DrawMainFram(canvas);
		shoppanel.Draw(canvas);
		
		
		unlockcell.SetString(T.PLAY_NUMCELL_LOCK+" Unlocked cell left");
		
		luckkycell.SetString("Your chance: " + T.PLAY_LUCKY);
		manasize.SetString("Your mana : " + T.PLAY_MANASIZE);
		boomsize.SetString("Your boom range : " + T.PLAY_BOOM_LEVEL);
		magicsize.SetString("Your magic range : " + T.PLAY_MAGIC_LEVEL);
		
		if(T.PLAY_NUMCELL_LOCK>0)
			unlockcell.Draw(canvas);
		if(T.PLAY_LUCKY < 20)
			luckkycell.Draw(canvas);
		if(T.PLAY_MANASIZE<200)
			manasize.Draw(canvas);
		if(T.PLAY_BOOM_LEVEL <6)
			boomsize.Draw(canvas);
		if(T.PLAY_MAGIC_LEVEL <6)
			magicsize.Draw(canvas);
	}
	protected void DrawMainFram(Canvas canvas)
	{
		int width_step=T.MARGIN_WIDTH;
		
		T.paint.setColor(Color.DKGRAY);
		canvas.drawRect(width_step, 0, width_step + T.BORDER_WIDTH, T.DISPLAY_HEIGHT, T.paint);
		
		width_step += T.BORDER_WIDTH;
		//T.paint.setColor(Color.WHITE);
		//canvas.drawRect(width_step, 0, width_step + T.GAME_SCREEN_WIDTH, T.GAME_SCREEN_HEIGHT, T.paint);
		
		
		width_step += T.GAME_SCREEN_WIDTH;
		T.paint.setColor(Color.DKGRAY);
		canvas.drawRect(width_step, 0, width_step + T.BORDER_WIDTH, T.DISPLAY_HEIGHT, T.paint);
		//draw menu
		
		T.mat = new Matrix();
		T.mat.postScale(T.MENU_WIDTH*1.0f/300,T.MENU_WIDTH*2.0f/600);
		T.mat.postTranslate(T.PANEL_MIN_X, T.PANEL_MIN_Y);
		canvas.drawBitmap(T.bitmap_frame_panel, T.mat, null);
		
	}
	public void touch(MotionEvent mo)
	{
		
		//Log.d("here", "ddddddd");
		int action = mo.getAction();
		int actionCode = action & MotionEvent.ACTION_MASK;
		temp_x = (int)mo.getX();
		temp_y = (int)mo.getY();
	
		if(temp_x>T.PANEL_MIN_X &&temp_x < T.PANEL_MAX_X)
		{
			if(temp_y>T.PANEL_MIN_Y &&temp_y < T.PANEL_MAX_Y)
				shoppanel.touch(mo);
		}
		else
		{
			
			
				if(unlockcell.Kick(mo) == true)
				{
					if(T.PLAY_NUMCELL_LOCK>0)
					{
						T.notice.SetString("Do you want to buy", "5000");
						T.notice.DoNotice(2,CallBackFunction.BUY_CELL);
						ResetAllMouseAlpha();
						return;
					}
				}
			
			else 
		
			if(luckkycell.Kick(mo) == true)
			{
					if(T.PLAY_LUCKY < 20)
					{
				T.notice.SetString("Do you want to buy", "10000");
				T.notice.DoNotice(2,CallBackFunction.BUY_LUCKY);
				ResetAllMouseAlpha();
				return;
					}
			}	
				
			else if(manasize.Kick(mo) == true)
			{
				if(T.PLAY_MANASIZE<200)
				{
					T.notice.SetString("Do you want to buy", "20000");
					T.notice.DoNotice(2,CallBackFunction.BUY_MANA);
					ResetAllMouseAlpha();
					return;
				}
			}	
			
			else if(boomsize.Kick(mo) == true)
			{
				if(T.PLAY_BOOM_LEVEL <6)
				{
					T.notice.SetString("Do you want to buy", "5000");
					T.notice.DoNotice(2,CallBackFunction.BUY_BOOM);
					ResetAllMouseAlpha();
					return;
				}
			}	
				
			else if(magicsize.Kick(mo) == true)
			{
				if(T.PLAY_MAGIC_LEVEL <6)
				{
					T.notice.SetString("Do you want to buy", "30000");
					T.notice.DoNotice(2,CallBackFunction.BUY_MAGIC);
					ResetAllMouseAlpha();
					return;
				}
			}	
			//else
				//ResetAllMouseAlpha();
			if(actionCode == MotionEvent.ACTION_UP)
				ResetAllMouseAlpha();
		}
	}
	static public void ResetAllMouseAlpha()
	{
		unlockcell.anpla = 255;
		luckkycell.anpla = 255;
		manasize.anpla = 255;
		shoppanel.but_menu.anpla = 255;
		boomsize.anpla = 255;
		magicsize.anpla = 255;
	}
	
}
